package com.example.d15_homework.homework03;

public enum ChargeType {
    // 枚举第一行必须罗列枚举对象
    CHARGE_TYPE_CHARGED(10131001, "自费"),
    CHARGE_TYPE_FREE(10131002, "免费"),
    CHARGE_TYPE_MEMBER_RIGHTS(10131003, "会员权益");

    private final int code;
    private final String name;

    // 构造方法，用于初始化属性
    ChargeType(int code, String name) {
        this.code = code;
        this.name = name;
    }

    public int getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    // 静态方法：根据标号获取付款名称
    public static String getChargeTypeNameByCode(int code) {
        // ChargeType.values()可以获取到所有的枚举对象
        for (ChargeType type : ChargeType.values()) {
            if (type.getCode() == code) {
                return type.getName();
            }
        }
        throw new IllegalArgumentException("未知的付款方式标号: " + code);
    }
}
